bitkeeper revision 1.1081.1.2 (40f55de2NRzSVtT27hdCdG3fbdnqGg)
authormjw@wray-m-3.hpl.hp.com <mjw@wray-m-3.hpl.hp.com>
Wed, 14 Jul 2004 16:22:58 +0000 (16:22 +0000)
committermjw@wray-m-3.hpl.hp.com <mjw@wray-m-3.hpl.hp.com>
Wed, 14 Jul 2004 16:22:58 +0000 (16:22 +0000)
Allow console port for a domain to be specified.

tools/python/xen/xend/XendConsole.py
tools/python/xen/xend/XendDomainInfo.py
tools/python/xen/xend/server/console.py
tools/python/xen/xm/create.py

index 440b6275623e89ffe3db4c57555b93191ae0899a..9cc57ff45668f716a219997d4d6e0aa67c25a013 100644 (file)
@@ -154,8 +154,8 @@ class XendConsole:
         self.refresh()
         return self.console.values()
     
-    def console_create(self, dom):
-        consinfo = daemon.console_create(dom)
+    def console_create(self, dom, console_port=None):
+        consinfo = daemon.console_create(dom, console_port=console_port)
         info = self._new_console(consinfo)
         return info
     
index d63034f3ffa2fbd329298169bd364c0a45014060..5b6677b1978057f0c89aa92efd1681356e1756c7 100644 (file)
@@ -349,6 +349,7 @@ class XendDomainInfo:
         self.migrate = None
         #Whether to auto-restart
         self.restart_mode = RESTART_ONREBOOT
+        self.console_port = None
 
     def setdom(self, dom):
         self.dom = int(dom)
@@ -403,7 +404,12 @@ class XendDomainInfo:
         self.config = config
         try:
             self.name = sxp.child_value(config, 'name')
-            self.memory = int(sxp.child_value(config, 'memory', '128'))
+            if self.name is None:
+                raise VmError('missing domain name')
+            self.memory = int(sxp.child_value(config, 'memory'))
+            if self.memory is None:
+                raise VmError('missing memory size')
+            self.configure_console()
             self.configure_restart()
             self.configure_backends()
             image = sxp.child_value(config, 'image')
@@ -617,7 +623,7 @@ class XendDomainInfo:
             if ramdisk and not os.path.isfile(ramdisk):
                 raise VmError('Kernel ramdisk does not exist: %s' % ramdisk)
         self.init_domain()
-        self.console = xendConsole.console_create(self.dom)
+        self.console = xendConsole.console_create(self.dom, console_port=self.console_port)
         self.build_domain(ostype, kernel, ramdisk, cmdline, vifs_n)
         self.image = kernel
         self.ramdisk = ramdisk
@@ -680,6 +686,15 @@ class XendDomainInfo:
             self.config.remove(['device', dev_config])
         dev.destroy()
 
+    def configure_console(self):
+        x = sxp.child_value(self.config, 'console')
+        if x:
+            try:
+                port = int(x)
+            except:
+                raise VmError('invalid console:' + str(x))
+            self.console_port = port
+
     def configure_restart(self):
         r = sxp.child_value(self.config, 'restart', RESTART_ONREBOOT)
         if r not in restart_modes:
index 77f6343c3d10c427da9bc030255accfa28525573..4769e91bfe0305503cf773558bf399be02a6bbb5 100755 (executable)
@@ -6,6 +6,7 @@ from twisted.protocols import telnet
 
 from xen.lowlevel import xu
 
+from xen.xend.XendError import XendError
 from xen.xend import EventServer
 eserver = EventServer.instance()
 
@@ -77,6 +78,9 @@ class ConsoleControllerFactory(controller.ControllerFactory):
     def createInstance(self, dom, console_port=None):
         if console_port is None:
             console_port = CONSOLE_PORT_BASE + dom
+        for c in self.getInstances():
+            if c.console_port == console_port:
+                raise XendError('console port in use: ' + str(console_port))
         console = ConsoleController(self, dom, console_port)
         self.addInstance(console)
         eserver.inject('xend.console.create',
index 7c9dcb3db8b19799f629a010bfe1872674d4896b..ce56b75d9ca940e302f89159468e96298b95e01b 100644 (file)
@@ -68,38 +68,42 @@ gopts.opt('load', short='L', val='FILE',
           use='Domain saved state to load.')
 
 gopts.opt('dryrun', short='n',
-         fn=set_true, default=0,
-         use="""Dry run - print the config but don't create the domain.
+          fn=set_true, default=0,
+          use="""Dry run - print the config but don't create the domain.
 The defaults file is loaded and the SXP configuration is created and printed.         
 """)
 
 gopts.opt('console_autoconnect', short='c',
-         fn=set_true, default=0,
-         use="Connect to console after domain is created.")
+          fn=set_true, default=0,
+          use="Connect to console after domain is created.")
 
 gopts.var('name', val='NAME',
           fn=set_value, default=None,
           use="Domain name.")
 
 gopts.var('kernel', val='FILE',
-         fn=set_value, default=None,
-         use="Path to kernel image.")
+          fn=set_value, default=None,
+          use="Path to kernel image.")
 
 gopts.var('ramdisk', val='FILE',
-         fn=set_value, default='',
-         use="Path to ramdisk.")
+          fn=set_value, default='',
+          use="Path to ramdisk.")
 
 gopts.var('builder', val='FUNCTION',
-         fn=set_value, default='linux',
-         use="Function to use to build the domain.")
+          fn=set_value, default='linux',
+          use="Function to use to build the domain.")
 
 gopts.var('memory', val='MEMORY',
-         fn=set_value, default=128,
-         use="Domain memory in MB.")
+          fn=set_value, default=128,
+          use="Domain memory in MB.")
+
+gopts.var('console', val='PORT',
+          fn=set_int, default=None,
+          use="Console port to use. Default is 9600 + domain id.")
 
 gopts.var('restart', val='onreboot|always|never',
-         fn=set_value, default=None,
-         use="""Whether the domain should be restarted on exit.
+          fn=set_value, default=None,
+          use="""Whether the domain should be restarted on exit.
          - onreboot: restart on exit with shutdown code reboot
          - always:   always restart on exit, ignore exit code
          - never:    never restart on exit, ignore exit code
@@ -114,27 +118,27 @@ gopts.var('netif', val='no|yes',
           use="Make the domain a network interface backend.")
 
 gopts.var('disk', val='phy:DEV,VDEV,MODE',
-         fn=append_value, default=[],
-         use="""Add a disk device to a domain. The physical device is DEV,
+          fn=append_value, default=[],
+          use="""Add a disk device to a domain. The physical device is DEV,
          which is exported to the domain as VDEV. The disk is read-only if MODE
          is 'r', read-write if MODE is 'w'.
          The option may be repeated to add more than one disk.
          """)
 
 gopts.var('pci', val='BUS,DEV,FUNC',
-         fn=append_value, default=[],
-         use="""Add a PCI device to a domain, using given params (in hex).
+          fn=append_value, default=[],
+          use="""Add a PCI device to a domain, using given params (in hex).
          For example '-pci c0,02,1a'.
          The option may be repeated to add more than one pci device.
          """)
 
 gopts.var('ipaddr', val="IPADDR",
-         fn=append_value, default=[],
-         use="Add an IP address to the domain.")
+          fn=append_value, default=[],
+          use="Add an IP address to the domain.")
 
 gopts.var('vif', val="mac=MAC,bridge=BRIDGE,script=SCRIPT",
-         fn=append_value, default=[],
-         use="""Add a network interface with the given MAC address and bridge.
+          fn=append_value, default=[],
+          use="""Add a network interface with the given MAC address and bridge.
          The vif is configured by calling the given configuration script.
          If mac is not specified a random MAC address is used.
          If bridge is not specified the default bridge is used.
@@ -144,53 +148,53 @@ gopts.var('vif', val="mac=MAC,bridge=BRIDGE,script=SCRIPT",
          """)
 
 gopts.var('nics', val="NUM",
-         fn=set_int, default=1,
-         use="""Set the number of network interfaces.
+          fn=set_int, default=1,
+          use="""Set the number of network interfaces.
          Use the vif option to define interface parameters, otherwise
          defaults are used. Specifying vifs will increase the
          number of interfaces as needed.
          """)
 
 gopts.var('root', val='DEVICE',
-         fn=set_value, default='',
-         use="""Set the root= parameter on the kernel command line.
+          fn=set_value, default='',
+          use="""Set the root= parameter on the kernel command line.
          Use a device, e.g. /dev/sda1, or /dev/nfs for NFS root.""")
 
 gopts.var('extra', val="ARGS",
-         fn=set_value, default='',
-         use="Set extra arguments to append to the kernel command line.")
+          fn=set_value, default='',
+          use="Set extra arguments to append to the kernel command line.")
 
 gopts.var('ip', val='IPADDR',
-         fn=set_value, default='',
-         use="Set the kernel IP interface address.")
+          fn=set_value, default='',
+          use="Set the kernel IP interface address.")
 
 gopts.var('gateway', val="IPADDR",
-         fn=set_value, default='',
-         use="Set the kernel IP gateway.")
+          fn=set_value, default='',
+          use="Set the kernel IP gateway.")
 
 gopts.var('netmask', val="MASK",
-         fn=set_value, default = '',
-         use="Set the kernel IP netmask.")
+          fn=set_value, default = '',
+          use="Set the kernel IP netmask.")
 
 gopts.var('hostname', val="NAME",
-         fn=set_value, default='',
-         use="Set the kernel IP hostname.")
+          fn=set_value, default='',
+          use="Set the kernel IP hostname.")
 
 gopts.var('interface', val="INTF",
-         fn=set_value, default="eth0",
-         use="Set the kernel IP interface name.")
+          fn=set_value, default="eth0",
+          use="Set the kernel IP interface name.")
 
 gopts.var('dhcp', val="off|dhcp",
-         fn=set_value, default='off',
-         use="Set the kernel dhcp option.")
+          fn=set_value, default='off',
+          use="Set the kernel dhcp option.")
 
 gopts.var('nfs_server', val="IPADDR",
-         fn=set_value, default=None,
-         use="Set the address of the NFS server for NFS root.")
+          fn=set_value, default=None,
+          use="Set the address of the NFS server for NFS root.")
 
 gopts.var('nfs_root', val="PATH",
-         fn=set_value, default=None,
-         use="Set the path of the root NFS directory.")
+          fn=set_value, default=None,
+          use="Set the path of the root NFS directory.")
 
 def strip(pre, s):
     """Strip prefix 'pre' if present.
@@ -244,7 +248,7 @@ def randomMAC():
     The remaining 3 fields are random, with the first bit of the first
     random field set 0.
 
-    returns array of 6 ints
+    returns MAC address string
     """
     mac = [ 0xaa, 0x00, 0x00,
             random.randint(0x00, 0x7f),
@@ -300,6 +304,8 @@ def make_config(vals):
         config.append(['backend', ['netif']])
     if vals.restart:
         config.append(['restart', vals.restart])
+    if vals.console:
+        config.append(['console', vals.console])
     
     configure_image(config, vals)
     config_devs = []
@@ -349,6 +355,7 @@ def preprocess_vifs(opts, vals):
 
 def preprocess_ip(opts, vals):
     setip = (vals.hostname or vals.netmask
+             or vals.nfs_server
              or vals.gateway or vals.dhcp or vals.interface)
     if not setip: return
     dummy_nfs_server = '1.2.3.4'